﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.ui {
    import flash.events.*;
    import reprise.events.*;
    import flash.display.*;
    import flash.geom.*;
    import flash.utils.*;

    public class UIObject extends Sprite {

        protected var m_initialized:Boolean;
        protected var m_delayedMethods:Array;
        protected var m_childArrayCleanupNeeded:Boolean;
        protected var m_isRendered:Boolean = true
        protected var m_tooltipRenderer:String = null
        protected var m_contentDisplay:DisplayObjectContainer;
        protected var m_class:Class;
        protected var m_filters:Array;
        protected var m_lastKeyChild:UIObject;
        protected var m_isLastChild:Boolean;
        protected var m_nextKeyView:UIObject;
        protected var m_firstKeyChild:UIObject;
        protected var m_elementType:String;
        protected var m_canBecomeKeyView:Boolean;
        protected var m_children:Array;
        protected var m_tooltipData:Object = null
        protected var m_parentElement:UIObject;
        protected var m_visible:Boolean = true
        protected var m_isFirstChild:Boolean;
        protected var m_isInvalidated:Boolean;
        protected var m_isValidating:Boolean;
        protected var m_keyOrder:Array;
        protected var m_firstDraw:Boolean;
        protected var m_tabIndex:int;
        protected var m_tooltipDelay:int = 0
        protected var m_previousKeyView:UIObject;
        protected var m_rootElement:DocumentView;

        protected static var g_elementIDCounter:int = 0;

        public function UIObject(){
            var _local1:String;
            m_children = [];
            super();
            m_class = Class(Object(this).constructor);
            if (m_class["className"]){
                m_elementType = m_class["className"];
            } else {
                _local1 = getQualifiedClassName(this);
                m_elementType = _local1.substr((_local1.indexOf("::") + 2));
            };
            preinitialize();
        }
        protected function realStage():Stage{
            return (super.stage);
        }
        public function getElementsByTagName(_arg1:String):Array{
            var _local4:Array;
            var _local6:UIObject;
            _arg1 = _arg1.toLowerCase();
            var _local2:int = m_children.length;
            var _local3:Array = [];
            var _local5:int;
            while (_local5 < _local2) {
                _local6 = (m_children[_local5] as UIObject);
                if (_local6.m_elementType.toLowerCase() == _arg1){
                    _local3.push(_local6);
                };
                _local4 = _local6.getElementsByTagName(_arg1);
                if (_local4.length){
                    _local3 = _local3.concat(_local4);
                };
                _local5++;
            };
            return (_local3);
        }
        public function children():Array{
            return (m_children);
        }
        protected function setRootElement(_arg1:DocumentView):void{
            var _local2:UIObject;
            if (_arg1 == m_rootElement){
                return;
            };
            m_rootElement = _arg1;
            for each (_local2 in m_children) {
                _local2.setRootElement(_arg1);
            };
        }
        protected function unregisterChildView(_arg1:UIObject):void{
            var _local2:int = m_children.indexOf(_arg1);
            if (_local2 == -1){
                return;
            };
            if (m_isValidating){
                m_childArrayCleanupNeeded = true;
                m_children[_local2] = null;
            } else {
                m_children.splice(_local2, 1);
            };
            _arg1.dispatchEvent(new DisplayEvent(DisplayEvent.REMOVED_FROM_DOCUMENT, true));
            ((_arg1.parent) && (_arg1.parent.removeChild(_arg1)));
            _arg1.m_parentElement = null;
            _arg1.setRootElement(null);
            invalidate();
        }
        public function isRendered():Boolean{
            return (m_isRendered);
        }
        public function visibility():Boolean{
            return (m_visible);
        }
        protected function validateElement(_arg1:Boolean=false, _arg2:Boolean=false):void{
            if (((((((((m_parentElement) && (!((m_parentElement == this))))) && (m_parentElement.m_isInvalidated))) || (!(m_isInvalidated)))) && (!(_arg1)))){
                return;
            };
            m_isInvalidated = false;
            m_isValidating = true;
            validateBeforeChildren();
            if (!m_isRendered){
                visible = false;
                m_isValidating = false;
                finishValidation();
                return;
            };
            validateChildren();
            validateAfterChildren();
            calculateKeyLoop();
            if (m_firstDraw){
                visible = m_visible;
                m_firstDraw = false;
                beforeFirstDraw();
            };
            draw();
            finishValidation();
            dispatchEvent(new DisplayEvent(DisplayEvent.VALIDATION_COMPLETE));
        }
        public function removeFilter(_arg1:Object):void{
            if (!m_filters){
                return;
            };
            var _local2:int = m_filters.indexOf(_arg1);
            if (_local2 != -1){
                m_filters.splice(_local2, 1);
                m_contentDisplay.filters = m_filters;
            };
        }
        public function setTooltipRenderer(_arg1:String):void{
            m_tooltipRenderer = _arg1;
        }
        public function get document():DocumentView{
            return (m_rootElement);
        }
        public function setVisibility(_arg1:Boolean):void{
            m_visible = _arg1;
            if (!m_firstDraw){
                visible = _arg1;
            };
            dispatchEvent(new DisplayEvent(DisplayEvent.VISIBLE_CHANGED));
        }
        public function nextKeyView():UIObject{
            if (m_children.length){
                return (m_firstKeyChild);
            };
            return (m_nextKeyView);
        }
        protected function validateChildren():void{
            var i:int;
            while (i < m_children.length) {
                validateChild(UIObject(m_children[i]));
                i = (i + 1);
            };
            if (m_childArrayCleanupNeeded){
                m_children = m_children.filter(function (_arg1:Object, _arg2:int, _arg3:Array):Boolean{
                    return (!((_arg1 == null)));
                });
                m_childArrayCleanupNeeded = false;
            };
        }
        public function invalidate():void{
            if (!m_rootElement){
                m_isInvalidated = true;
                return;
            };
            if (((((((!(m_parentElement)) || (!(m_parentElement.m_isInvalidated)))) && (!(m_isInvalidated)))) && (m_rootElement))){
                m_rootElement.markChildAsInvalid(this);
            };
            m_isInvalidated = true;
        }
        protected function createChildren():void{
        }
        public function hide(... _args):void{
            hide_complete();
        }
        protected function draw():void{
        }
        override public function removeChildAt(_arg1:int):DisplayObject{
            var _local2:UIObject = m_children[_arg1];
            if (_local2){
                unregisterChildView(_local2);
                return (_local2);
            };
            return (super.removeChildAt(_arg1));
        }
        public function tooltipData():Object{
            return (m_tooltipData);
        }
        public function tooltipDelay():int{
            return (m_tooltipDelay);
        }
        protected function show_complete(_arg1:Event=null):void{
            dispatchEvent(new DisplayEvent(DisplayEvent.SHOW_COMPLETE));
        }
        protected function validateBeforeChildren():void{
        }
        protected function beforeFirstDraw():void{
        }
        public function elementType():String{
            return (m_elementType);
        }
        public function elementForName(_arg1:String):UIObject{
            var _local2:UIObject;
            for each (_local2 in m_children) {
                if (_local2.name == _arg1){
                    return (_local2);
                };
            };
            return (null);
        }
        protected function calculateKeyLoop():void{
            var _local2:int;
            var _local4:UIObject;
            var _local5:UIObject;
            if (m_children.length == 0){
                return;
            };
            var _local1:int = m_children.length;
            var _local3:Array = m_children.concat();
            _local3.sortOn(["tabIndex", "y", "x"], Array.NUMERIC);
            _local2 = 0;
            while (_local2 < _local1) {
                _local4 = UIObject(_local3[_local2]);
                if (_local2 < (_local1 - 1)){
                    _local5 = UIObject(_local3[(_local2 + 1)]);
                } else {
                    _local5 = ((m_parentElement == this)) ? this : m_nextKeyView;
                };
                _local4.setNextKeyView(_local5);
                _local2++;
            };
            m_firstKeyChild = _local3[0];
            m_lastKeyChild = _local3[(_local1 - 1)];
            m_firstKeyChild.setPreviousKeyView(this);
            m_keyOrder = _local3;
        }
        public function getPositionRelativeToContext(_arg1:UIObject):Point{
            return (getPositionRelativeToDisplayObject(_arg1.m_contentDisplay));
        }
        override public function toString():String{
            return ((((((m_parentElement) && ((m_parentElement.toString() + ".")))) || ("")) + name));
        }
        public function setNextKeyView(_arg1:UIObject):void{
            m_nextKeyView = _arg1;
            var _local2:UIObject = this;
            if (m_children.length){
                ((m_lastKeyChild) && (m_lastKeyChild.setNextKeyView(_arg1)));
                _local2 = m_lastKeyChild;
            };
            if (_arg1){
                _arg1.setPreviousKeyView(_local2);
            };
        }
        protected function preinitialize():void{
            name = ((m_elementType + "_") + g_elementIDCounter++);
            m_delayedMethods = [];
            createDisplayClips();
            m_keyOrder = [];
            m_tabIndex = 0;
        }
        public function isHidden():Boolean{
            return (!(visibility()));
        }
        public function addFilter(_arg1:Object):void{
            if (!m_filters){
                m_filters = [];
            };
            if (m_filters.indexOf(_arg1) != -1){
                return;
            };
            m_filters.push(_arg1);
            m_contentDisplay.filters = m_filters;
        }
        public function hasHiddenAncestors():Boolean{
            if (!stage){
                return (true);
            };
            var _local1:UIObject = this;
            while (_local1.m_parentElement != _local1) {
                _local1 = _local1.m_parentElement;
                if (!_local1.visibility()){
                    return (true);
                };
            };
            return (false);
        }
        protected function addChildToContentDisplay(_arg1:UIObject, _arg2:int):void{
            m_contentDisplay.addChildAt(_arg1, Math.min(m_contentDisplay.numChildren, _arg2));
        }
        protected function validateAfterChildren():void{
        }
        public function setTooltipData(_arg1:Object):void{
            m_tooltipData = _arg1;
            dispatchEvent(new DisplayEvent(DisplayEvent.TOOLTIPDATA_CHANGED));
        }
        override public function addChildAt(_arg1:DisplayObject, _arg2:int):DisplayObject{
            var _local3:UIObject;
            if ((_arg1 is UIObject)){
                _local3 = UIObject(_arg1);
                if (_local3.m_parentElement == this){
                    return (_local3);
                };
                if (_local3.m_parentElement){
                    _local3.m_parentElement.unregisterChildView(_local3);
                };
                addChildToContentDisplay(_local3, _arg2);
                _local3.setParent(this);
                if (_arg2 == 0){
                    _local3.m_isFirstChild = true;
                    if (m_children.length){
                        UIObject(m_children[0]).m_isFirstChild = false;
                    };
                } else {
                    _local3.m_isFirstChild = false;
                };
                if (_arg2 == m_children.length){
                    _local3.m_isLastChild = true;
                    if (m_children.length){
                        UIObject(m_children[(m_children.length - 1)]).m_isLastChild = false;
                    };
                } else {
                    _local3.m_isLastChild = false;
                };
                m_children.splice(_arg2, 0, _arg1);
                invalidate();
            } else {
                super.addChildAt(_arg1, _arg2);
            };
            return (_arg1);
        }
        protected function initialize():void{
            m_initialized = true;
            m_firstDraw = true;
            visible = false;
            createChildren();
        }
        public function setFocus(_arg1:Boolean, _arg2:String):void{
        }
        protected function finishValidation():void{
            m_isValidating = false;
        }
        public function nextValidKeyView():UIObject{
            var _local1:UIObject;
            if (visibility()){
                _local1 = nextKeyView();
            } else {
                _local1 = m_nextKeyView;
            };
            while (true) {
                if ((((((_local1 == null)) || ((_local1 == this)))) || (_local1.canBecomeKeyView()))){
                    return (_local1);
                };
                _local1 = _local1.nextKeyView();
            };
            return (null);
        }
        public function remove(... _args):void{
            ((m_parentElement) && (m_parentElement.unregisterChildView(this)));
        }
        public function previousValidKeyView():UIObject{
            var _local1:UIObject = previousKeyView();
            while (true) {
                if ((((((_local1 == null)) || ((_local1 == this)))) || (_local1.canBecomeKeyView()))){
                    return (_local1);
                };
                _local1 = _local1.previousKeyView();
            };
            return (null);
        }
        protected function hide_complete(_arg1:Event=null):void{
            setVisibility(false);
            dispatchEvent(new DisplayEvent(DisplayEvent.HIDE_COMPLETE));
        }
        protected function validateChild(_arg1:UIObject):void{
            _arg1.validateElement(true);
        }
        public function setParent(_arg1:UIObject):UIObject{
            m_parentElement = _arg1;
            setRootElement(_arg1.m_rootElement);
            if (!m_initialized){
                initialize();
            };
            invalidate();
            return (this);
        }
        public function isOffScreen():Boolean{
            if (!stage){
                return (true);
            };
            var _local1:Boolean = ((visibility()) && (!(hasHiddenAncestors())));
            if (!_local1){
                return (true);
            };
            var _local2:Rectangle = getBounds(stage);
            return (!((((((((_local2.right > 0)) || ((_local2.left < stage.stageWidth)))) || ((_local2.bottom > 0)))) || ((_local2.top < stage.stageHeight)))));
        }
        public function previousKeyView():UIObject{
            return (m_previousKeyView);
        }
        protected function createDisplayClips():void{
            m_contentDisplay = new Sprite();
            m_contentDisplay.name = "content";
            super.addChild(m_contentDisplay);
        }
        function validation_execute():void{
            var _local1:Function;
            validateElement();
            for each (_local1 in m_delayedMethods) {
                _local1();
            };
            m_delayedMethods = [];
        }
        public function setTooltipDelay(_arg1:int):void{
            m_tooltipDelay = _arg1;
        }
        public function forceRedraw():void{
            var _local1:UIObject = this;
            while (((_local1.m_parentElement) && (!((_local1.m_parentElement == _local1))))) {
                _local1 = _local1.m_parentElement;
                if (_local1.m_isInvalidated){
                    log(((((((("w Be ye warned: The element you are calling " + "forceRedraw on has invalid ascendants. This might cause ") + "styling and all sorts of other things not to work as ") + "expected. Consider calling m_rootElement.forceRedraw ") + "instead.\nAfflicted element: ") + this) + "\ninvalid parent: ") + _local1));
                    break;
                };
            };
            m_rootElement.markChildAsValid(this);
            validateElement(true);
        }
        public function getPositionRelativeToDisplayObject(_arg1:DisplayObject):Point{
            var _local2:Point = new Point(0, 0);
            _local2 = localToGlobal(_local2);
            _local2 = _arg1.globalToLocal(_local2);
            return (_local2);
        }
        public function tooltipRenderer():String{
            return (m_tooltipRenderer);
        }
        public function setPreviousKeyView(_arg1:UIObject):void{
            m_previousKeyView = _arg1;
        }
        public function canBecomeKeyView():Boolean{
            return (((m_canBecomeKeyView) && (!(isOffScreen()))));
        }
        public function clearFilters():void{
            m_contentDisplay.filters = null;
        }
        public function parentElement():UIObject{
            return (((m_parentElement == this)) ? null : m_parentElement);
        }
        override public function removeChild(_arg1:DisplayObject):DisplayObject{
            if ((_arg1 is UIObject)){
                unregisterChildView(UIObject(_arg1));
                return (_arg1);
            };
            return (super.removeChild(_arg1));
        }
        public function isValid():Boolean{
            return (m_isInvalidated);
        }
        override public function addChild(_arg1:DisplayObject):DisplayObject{
            if ((_arg1 is UIObject)){
                return (addChildAt(_arg1, m_children.length));
            };
            return (super.addChild(_arg1));
        }
        public function show(... _args):void{
            setVisibility(true);
            show_complete();
        }
        override public function get stage():Stage{
            if (super.stage){
                return (super.stage);
            };
            return ((((m_parentElement) && (m_rootElement))) ? UIObject(m_rootElement).realStage() : null);
        }
        public function applicationURL():String{
            return (loaderInfo.url);
        }

    }
}//package reprise.ui 
